/*
 * @Description: 订单分货
 * @Version: 1.0
 * @Autor: c-jack.qian
 * @Date: 2021-02-24 11:56:54
 * @LastEditors: c-jack.qian
 * @LastEditTime: 2021-04-25 15:02:30
 */
import { FieldType } from 'choerodon-ui/pro/lib/data-set/enum';
import commonConfigStore from '@common/config/commonConfig';

import intl from 'utils/intl';
const O2_OM = process.env.NODE_ENV === 'development' ? '/o2om-c' : commonConfigStore.O2_OM;

// import moment from 'moment';
import { resetMonth } from '@src/utils/utilsFun';

const orderDistributionDS = () => ({
    autoQuery: true,
    selection: 'multiple',
    primaryKey: 'id',
    transport: {
        read: config => {
            const { data } = config;
            const { quotaMonth } = data;
            // 截掉月份后面的时间
            const submitData = resetMonth(data, quotaMonth, 'quotaMonth')
            return {
                ...config,
                data: {
                    ...submitData,
                },
                url: `${O2_OM}/v1/quota-orders`,
                method: 'get',
            };
        },
        destroy: config => {
            return {
                ...config,
                url: `${O2_OM}/v1/quota-orders`,
                method: 'delete',
            };
        },
    },
    fields: [
        {
            name: 'quotaCode',
            type: FieldType.string,
            label: intl.get('dji.otc.om.view.field.quotaCode').d('分货单号'),
            required: true,
        },
        {
            name: 'quotaMonth',
            type: FieldType.month,
            label: intl.get('dji.otc.om.view.field.quotaMonth').d('配额月份'),
            required: true,
        },
        // {
        //     name: 'largeAreaObj',
        //     type: FieldType.object,
        //     label: intl.get('dji.otc.om.view.field.tagName').d('大区'),
        //     required: true,
        //     labelWidth: 120,
        //     checkValueOnOptionsChange: true,
        //     lookupUrl: `${O2_CM}/v1/cm-contract-permissions/get-largeArea-info`,
        //     ignore: 'always',
        // },
        {
            name: 'regionName',
            // bind: 'largeAreaObj.value',
            type: FieldType.string,
            label: intl.get('dji.otc.om.view.field.region').d('大区'),
        },
        // {
        //     name: 'areaObj',
        //     type: FieldType.object,
        //     label: intl.get('dji.otc.om.view.field.tagName').d('小区'),
        //     required: true,
        //     lookupUrl: `${O2_CM}/v1/cm-contract-permissions/get-area-info`,
        // },
        {
            name: 'areaName',
            // bind: 'areaObj.value',
            type: FieldType.string,
            label: intl.get('dji.otc.om.view.field.areaName').d('小区'),
        },
        {
            name: 'businessGroup',
            type: FieldType.string,
            label: intl.get('dji.otc.om.view.field.groupName').d('组别'),
            lookupCode: 'DJICM_GROUP',
        },
        {
            name: 'quotaStatusMeaning',
            type: FieldType.string,
            label: intl.get('dji.otc.om.view.field.quotaStatusMeaning').d('单据状态'),
            lookupCode: 'ADJUSTMENT_STATUS'
        },
        {
            name: 'approveStatusMeaning',
            type: FieldType.string,
            label: intl.get('dji.otc.om.view.field.approveStatusMeaning').d('审批状态'),
        },
        {
            name: 'createdBy',
            type: FieldType.string,
            label: intl.get('dji.otc.om.view.field.createdUserName').d('创建人'),
        },
        {
            name: 'creationDate',
            type: FieldType.string,
            label: intl.get('dji.otc.om.view.field.creationDate').d('创建时间'),
        },
    ],
    queryFields: [
        {
            name: 'quotaCode',
            type: FieldType.string,
            label: intl.get('dji.otc.om.view.field.quotaCode').d('分货单号'),
        },
        {
            name: 'dateObj',
            type: FieldType.date,
            label: intl.get('dji.otc.om.view.field.documentTime').d('单据时间'),
            range: ['start', 'end'],
            ignore: 'always'
        },
        {
            label: intl.get('dji.otc.om.view.field.effectiveDate').d('生效日期'),
            name: 'creationDateFrom',
            type: FieldType.date,
            bind: 'dateObj.start',
        },
        {
            label: intl.get('dji.otc.om.view.field.invalidDate').d('失效日期'),
            name: 'creationDateTo',
            type: FieldType.date,
            bind: 'dateObj.end',
        },
        {
            name: 'quotaStatusCode',
            type: FieldType.string,
            label: intl.get('dji.otc.om.view.field.quotaStatusMeaning').d('单据状态'),
            lookupCode: 'DJISM.ADJUSTMENT_STATUS'
        },
        {
            name: 'businessGroupCode',
            type: FieldType.string,
            label: intl.get('dji.otc.om.view.field.groupName').d('组别'),
            lookupCode: 'DJICM_GROUP',
        },
        {
            name: 'quotaMonth',
            type: FieldType.month,
            label: intl.get('dji.otc.om.view.field.quotaMonth').d('调整月份'),
            // defaultValue: moment().format("YYYY MM"),
        },
        {
            name: 'createdBy',
            type: FieldType.string,
            label: intl.get('dji.otc.om.view.field.createdUserName').d('制单人'),
        },
        {
            name: 'approvalStatusCode',
            type: FieldType.string,
            lookupCode: 'DJISM.ADJUSTMENT_STATUS',
            label: intl.get('dji.otc.om.view.field.approveStatusMeaning').d('审批状态'),
        },
    ],
});

const resultDetailDS = () => ({
    autoCreate: true,
    dataToJSON: 'normal',
    transport: {
        submit: config => {
            return {
                ...config,
                data: config.data[0],
                url: `${O2_OM}/v1/quota-plans/confirm`,
                method: 'POST',
            };
        },
    },
    fields: [
        {
            name: 'createTime',
            type: FieldType.string,
            label: intl.get('dji.otc.om.view.field.improtTime').d('导入时间'),
            required: true,
        },
        {
            name: 'importMode',
            type: FieldType.string,
            label: intl.get('dji.otc.om.view.field.importMode').d('导入方式'),
            required: true,
        },
        {
            name: 'quantity ',
            type: FieldType.string,
            label: intl.get('dji.otc.om.view.field.importQuantity').d('导入数量'),
            required: true,
        },
    ],
});

export { orderDistributionDS, resultDetailDS };
